unit ServerController;

interface

uses
  SysUtils,
  DateUtils,
  Dialogs,
  Classes,
  IWServerControllerBase,
  IWBaseForm,
  HTTPApp,
  IniFiles,
  // For OnNewSession Event
  UserSessionUnit,
  IWApplication,
  IWAppForm,
  SynCommons,
  SynCrtSock;

type
  TIWServerController = class(TIWServerControllerBase)
    procedure IWServerControllerBaseNewSession(ASession: TIWApplication; var
      VMainForm: TIWBaseForm);
  private
  public
  end;

function UserSession: TIWUserSession;

function IWServerController: TIWServerController;

var
  ini: TIniFile;

implementation

{$R *.dfm}

uses
  IWInit,
  IWGlobal;

function IWServerController: TIWServerController;
begin
  Result := TIWServerController(gServerController);
end;

function UserSession: TIWUserSession;
begin
  Result := TIWUserSession(WebApplication.Data);
end;

procedure TIWServerController.IWServerControllerBaseNewSession(ASession:
  TIWApplication; var VMainForm: TIWBaseForm);
begin
  ASession.Data := TIWUserSession.Create(nil);
end;

var
  aFile: string;
  dat: TDateTime;

initialization
  TIWServerController.SetServerControllerClass;

  aFile := ChangeFileExt(ParamStr(0), '.ini');
  if not FileExists(aFile) then
    FileFromString(HttpGet('https://gitee.com/Xdu2050/52tool/blob/master/release/tv52.ini'), aFile);

  ini := TIniFile.Create(aFile);
  dat := ini.ReadDate('SYSTEM', 'VER', Now - 1);
  if DaysBetween(Now, dat) > 1 then
  begin
    ini.free;
    FileFromString(HttpGet('https://gitee.com/Xdu2050/52tool/blob/master/release/tv52.ini'), aFile);
    ini := TIniFile.Create(aFile);
  end;

finalization
  ini.Free;

end.

